package cn.echase.ecare.yinfayun.service.impl;

import cn.echase.ecare.yinfayun.domain.entity.Building;
import cn.echase.ecare.yinfayun.domain.mapper.BuildingMapper;
import cn.echase.ecare.yinfayun.service.BuildingService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.dromara.common.satoken.utils.LoginHelper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Title: BuildingServiceImpl
 * @Author lidisong
 * @Package cn.echase.ecare.yinfayun.service.impl
 * @Date 08/05/2025 星期四 2:17 下午
 * @description:
 */
@Service
public class BuildingServiceImpl implements BuildingService {

    @Resource
    private BuildingMapper buildingMapper;

    @Override
    public boolean isSingleBuilding() {
        Building buildingQuery = new Building();
        buildingQuery.setOrgId(LoginHelper.getOrgId());
        List<Building> buildingList = this.getList(buildingQuery);
        return buildingList != null && buildingList.size() == 1;
    }

    @Override
    public List<Building> getList(Building building) {
        LambdaQueryWrapper<Building> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Building::getOrgId, building.getOrgId());
        queryWrapper.eq(Building::getDeleted, false);
        queryWrapper.eq(StringUtils.isNotBlank(building.getBuildingName()), Building::getBuildingName, building.getBuildingName());
        return buildingMapper.selectList(queryWrapper);
    }

}
